//引入axios
import request from '@/utils/requset';
//商品分类数据列表
async function getcategories(val?: any) {
  if (val !== undefined) {
    const data = await request(
      `http://106.12.150.223:8090/api/private/v1/categories`,
      'GET',
      {
        type: val.type,
        pagenum: val.pagenum,
        pagesize: val.pagesize,
      }
    );
    return data;
  } else {
    const data = await request(
      `http://106.12.150.223:8090/api/private/v1/categories`,
      'GET'
    );
    return data;
  }
}
//商品分类参数列表
async function getfeilei(id: number | null, sel: string) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/categories/${id}/attributes`,
    'GET',
    {
      sel: sel,
    }
  );
  return data;
}
// 添加动态参数或者静态属性
async function getpost(id: number, name: string, sel: string, value?: string) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/categories/${id}/attributes`,
    'POST',
    {
      attr_name: name,
      attr_sel: sel,
      attr_vals: value,
    }
  );
  return data;
}
//查询列表
async function getchaxun(id: number) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/categories/${id}`,
    'GET'
  );
  return data;
}
//根据 ID 查询参数
async function getchaid(id: number, uid: number, sel: string, vals?: string) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/categories/${id}/attributes/${uid}`,
    'GET',
    {
      attr_sel: sel,
      attr_vals: vals,
    }
  );
  return data;
}
//编辑列表
async function putliebiao(
  id: number,
  uid: number,
  name: string,
  sel: string,
  vals?: string
) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/categories/${id}/attributes/:attrId/${uid}`,
    'PUT',
    {
      attr_name: name,
      attr_sel: sel,
      attr_vals: vals,
    }
  );
  return data;
}
//删除列表 categories/:id
async function delliebiaos(id: number) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/categories/${id}`,
    'DELETE'
  );
  return data;
}
//删除参数
async function delcslb(id: number, uid: number) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/categories/${id}/attributes/${uid}`,
    'DELETE'
  );
  return data;
}
//商品列表
async function getsplbs(id: number, uid: number, can: string) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/goods`,
    'GET',
    {
      query: can,
      pagenum: id,
      pagesize: uid,
    }
  );
  return data;
}
//添加商品
async function posttianjiashangpin(val: any) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/goods`,
    'POST',
    val
  );
  return data;
}
//删除商品
async function delshangpins(id: number) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/goods/${id}`,
    'DELETE'
  );
  return data;
}

export default {
  getcategories,
  getfeilei,
  getpost,
  putliebiao,
  getchaxun,
  delliebiaos,
  delcslb,
  getchaid,
  getsplbs,
  posttianjiashangpin,
  delshangpins,
};
